from selenium.webdriver.chrome.webdriver import WebDriver
from selenium.webdriver.chromium.options import ChromiumOptions

WEB_DRIVER_PATH = '../bin/chromedriver.exe'


class WebDriverFactory:
    __instance: WebDriver = None

    @classmethod
    def get_instance(cls):
        if not cls.__instance:
            option = ChromiumOptions()
            # 使用headless无界面浏览器模式
            # option.add_argument('--headless')
            # option.add_argument('--disable-gpu')
            # 设置驱动路径
            option.binary_location = WEB_DRIVER_PATH
            cls.__instance = WebDriver()
            cls.__instance.maximize_window()
        return cls.__instance

    @staticmethod
    def stop(cls):
        if cls.__instance:
            cls.__instance.quit()
            cls.__instance = None
